package com.lagou.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Driver类型
 */
public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //加载配置文件和创建job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        //指定Driver类
        job.setJarByClass(SortDriver.class);
        //指定Mapper类型
        job.setMapperClass(SortMapper.class);
        //指定Reduce类型
        job.setReducerClass(SortReducer.class);
        //指定map输出key类型
        job.setMapOutputKeyClass(LongWritable.class);
        //指定map输出value类型
        job.setMapOutputValueClass(NullWritable.class);
        //指定reduce输出key类型
        job.setOutputKeyClass(LongWritable.class);
        //指定reduce输出value类型
        job.setOutputValueClass(LongWritable.class);
        //指定输入输出路径
        FileInputFormat.setInputPaths(job,new Path("E:\\作业\\formal-stage1-module1\\code\\data"));
        FileOutputFormat.setOutputPath(job,new Path("E:\\作业\\formal-stage1-module1\\code\\out"));
        //运行，返回状态
        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);



    }
}
